package com.yjz.springlearn.SpringAnnotation;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Desc 定义一个bean的Condition
 * @Author: jinzhong.yuan
 * @Date: 2019/2/18 14:37
 */
public class WindowsCondition implements Condition {
  @Override
  public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    Environment env = conditionContext.getEnvironment();
    String system = env.getProperty("os.name");
    System.out.println("系统环境为 ===" + system);
    // 系统环境在Windows才加载该bean到容器中
    if (system.contains("Windows 10")) {
      return true;
    }
    return false;
  }
}
